package com.lineage.data.item_etcitem.skill;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.datatables.ItemTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SkillSound;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Item;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class C3_EARTH_Item extends ItemExecutor {
  private static final Log _log = LogFactory.getLog(C3_EARTH_Item.class);
  
  private int _itemid = 44070;
  
  private int _count = 1;
  
  private int _time = 60;
  
  public static ItemExecutor get() {
    return new C3_EARTH_Item();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    try {
      if (item == null)
        return; 
      if (pc == null)
        return; 
      if (pc.getLevel() < 50) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fV50级以下无法使用!"));
        return;
      } 
      if (pc.hasSkillEffect(7005)) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fV不能与[火转术]共存!"));
        return;
      } 
      if (pc.hasSkillEffect(7006)) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fV不能与[水攻术]共存!"));
        return;
      } 
      if (pc.hasSkillEffect(7007)) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fV不能与[风伤术]共存!"));
        return;
      } 
      if (pc.hasSkillEffect(7008)) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fV[地气术]效果尚存:" + pc.getSkillEffectTimeSec(7008)));
        return;
      } 
      if (pc.hasSkillEffect(7009)) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fR属性技能尚未冷却"));
        return;
      } 
      if (this._itemid != 0) {
        L1ItemInstance ned_item = pc.getInventory().checkItemX(this._itemid, this._count);
        if (ned_item == null) {
          L1Item tgItem = ItemTable.get().getTemplate(this._itemid);
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(337, tgItem.getNameId()));
          return;
        } 
        pc.getInventory().removeItem(ned_item, this._count);
      } 
      pc.setSkillEffect(7009, (this._time + 30) * 1000);
      pc.setSkillEffect(7008, this._time * 1000);
      pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(pc.getId(), 213));
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public void set_set(String[] set) {
    try {
      this._itemid = Integer.parseInt(set[1]);
    } catch (Exception exception) {}
    try {
      this._count = Integer.parseInt(set[2]);
    } catch (Exception exception) {}
    try {
      this._time = Integer.parseInt(set[3]);
    } catch (Exception exception) {}
  }
}
